package com.xkdx.guangguang.fragment.shop.search;

import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xkdx.caipiao.R;
import com.xkdx.guangguang.ShopActivity;
import com.xkdx.guangguang.adapter.ShopAdapter;
import com.xkdx.guangguang.fragment.BaseFragment;
import com.xkdx.guangguang.fragment.shopinfo.ShopInfoFragment;
import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.module.statics.IConstants;
import com.xkdx.guangguang.shareclass.Shop;

public class SearchShopResultFragment extends BaseFragment {
	List<Shop> shopList;
	ListView listView;
	ImageView back;
	View view;
	ImageLoader imageLoader = ImageLoader.getInstance();
	DisplayImageOptions options;
	ShopAdapter adaptper;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		shopList = ((ShopActivity) getActivity()).getSearchShopList();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.search_shop_result, container, false);
		IConstants.hideInputMethodAways(getActivity(), view);
		findView();
		setOnClick();

		return view;
	}

	@Override
	public void findView() {
		listView = (ListView) view.findViewById(R.id.search_shop_result);
		back = (ImageView) view.findViewById(R.id.search_shop_back);
		adaptper = new ShopAdapter(getActivity(), shopList, imageLoader);
		listView.setAdapter(adaptper);
	}

	@Override
	public void setOnClick() {
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
				FragmentTransaction ft = getFragmentManager().beginTransaction();
				ShopInfoFragment shopInfoFragment = new ShopInfoFragment();
				Bundle b = new Bundle();
				b.putString("shopID", shopList.get(position).getShopID());
				shopInfoFragment.setArguments(b);
				ft.replace(R.id.fragment, shopInfoFragment);
				ft.addToBackStack(null);
				ft.commit();
			}
		});

		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				FragmentManager fm = getFragmentManager();
				fm.popBackStack();

			}
		});

	}

	@Override
	public void showLoading() {
		// TODO Auto-generated method stub

	}

	@Override
	public void showLoaded(HashMap<String, AbsModule> map) {
		// TODO Auto-generated method stub

	}

	@Override
	public void showClick(HashMap<String, AbsModule> map) {
		// TODO Auto-generated method stub

	}

	@Override
	public void showLoadMore(HashMap<String, AbsModule> map) {
		// TODO Auto-generated method stub

	}

}
